package com.dome.servlet;

import com.alibaba.fastjson.JSON;
import com.dome.bean.UserBean;
import com.dome.dao.UserDao;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/userLogin")
public class UserLoginWeb extends HttpServlet {
    UserDao dao=new UserDao();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");//设置字符输入流的编码
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        String name= req.getParameter("name");
        String pwd= req.getParameter("pwd");
        try {
            UserBean i=dao.findsUser(new UserBean(name,pwd));

           resp.getWriter().write(JSON.toJSONString(i));
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
